package com.txsj.scan.utils;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.txsj.scan.MyApplication;

public class PreferenceUtil {
    private static PreferenceUtil instance;
    private static SharedPreferences mSharedPreferences = null;
    private static Editor mEditor = null;
    public static final String MOBILE_VERIFY = "mobile_verify";//发送短信验证码返回的mobile_verify,在登录时需要用到
    public static final String USER_ID = "user_id";//用户id

    public static final String TOKEN = "token";//用户token
    public static final String BRAND_ID = "brand_id";//用户brand_id
    public static final String MOBILE = "mobile";//用户mobile
    public static final String USERNAME = "user_name"; //用户名称
    public static final String EMPLOYEEID = "employee_idd"; //员工id
    public static final String EMPLOYEENAME = "employee_name"; //员工名称
    public static final String COMID = "comid";//用户comid
    public static final String IS_LOGINED = "is_logined";//用户is_logined
    public static final String GOODS_IS_LOADED = "goods_is_loaded";//商品列表加载成功
    public static final String LABEL_IS_LOADED = "label_is_loaded";//标签列表加载成功
    public static final String FIRST_LOAD_LABEL_AND_GOODS = "first_load_label_and_goods";//第一次请求标签库和商品库（请求时间大概在半个小时左右）

    public static final String BRAND_NAME = "brand_name";//用户brand_name
    public static final String USER_NAME = "user_name";//用户user_name
    public static final String ROLE = "role";//用户role
    public static final String LOGO = "logo";//用户logo

    public static final String FIRST_ENTER_11 = "first_enter_11";//版本号为11的app,需要重新登录（比较特殊）

    private PreferenceUtil(){
        if (null == mSharedPreferences) {
            mSharedPreferences = android.preference.PreferenceManager.getDefaultSharedPreferences(MyApplication.getInstance()) ;
        }
    }

    public static PreferenceUtil getInstance(){
        if (null == instance){
            synchronized (PreferenceUtil.class){
                if (null == instance){
                    instance = new PreferenceUtil();
                }
            }
        }
        return instance;
    }

    public void removeKey(String key){
        mEditor = mSharedPreferences.edit();
        mEditor.remove(key);
        mEditor.commit();
    }
    
    public void removeAll(){
        mEditor = mSharedPreferences.edit();
        mEditor.clear();
        mEditor.commit();
    }

    public void commitString(String key, String value){
        mEditor = mSharedPreferences.edit();
        mEditor.putString(key, value);
        mEditor.commit();
    }
    
    public String getString(String key, String faillValue){
        return mSharedPreferences.getString(key, faillValue);
    }
    
    public void commitInt(String key, int value){
        mEditor = mSharedPreferences.edit();
        mEditor.putInt(key, value);
        mEditor.commit();
    }
    
    public int getInt(String key, int failValue){
        return mSharedPreferences.getInt(key, failValue);
    }
    
    public void commitLong(String key, long value){
        mEditor = mSharedPreferences.edit();
        mEditor.putLong(key, value);
        mEditor.commit();
    }
    
    public long getLong(String key, long failValue) {
        return mSharedPreferences.getLong(key, failValue);
    }
    
    public void commitBoolean(String key, boolean value){
        mEditor = mSharedPreferences.edit();
        mEditor.putBoolean(key, value);
        mEditor.commit();
    }
    
    public Boolean getBoolean(String key, boolean failValue){
        return mSharedPreferences.getBoolean(key, failValue);
    }
}
